package com.duobaoyu.dby.supply.message.listener.hander.order;

import com.alibaba.fastjson.JSON;
import com.duobaoyu.dby.supply.biz.producer.constant.SupplyChainMQConstants;
import com.duobaoyu.dby.supply.biz.producer.message.OrderSyncMessage;
import com.duobaoyu.dby.supply.biz.service.order.OrderService;
import com.duobaoyu.dby.supply.core.dinger.annotation.DingerTalk;
import com.duobaoyu.dby.supply.core.rocketmq.handler.AbstractClusterMessageHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.stereotype.Component;

/**
 * 订单同步消息
 * @author chenms
 * @date 2023/10/24 2:30 PM
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class OrderSyncMessageHandler extends AbstractClusterMessageHandler<OrderSyncMessage> {

    private final OrderService orderService;

    @Override
    public String getTopic() {
        return SupplyChainMQConstants.SupplyChainTopic.ORDER_TOPIC;
    }

    @Override
    public String getTag() {
        return SupplyChainMQConstants.SupplyChainTopic.OrderTag.SYNC_ORDER_INFO;
    }

    @Override
    @DingerTalk(title = "供应链订单同步消息Consumer")
    public boolean messageHandler(OrderSyncMessage orderSyncMessage, MessageExt messageExt) {
        if(log.isDebugEnabled()) {
            log.debug("开始处理订单同步消息, param={}", JSON.toJSONString(orderSyncMessage));
        }
        orderService.syncChannelOrderInfo(orderSyncMessage.getOrderSn());
        log.info("完成订单同步消息处理");
        return true;
    }
}
